﻿using System;
using System.Collections.Generic;
using Yummo.BlackBox;

namespace Yummo.BlackBox.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.Name = "Yummo.BlackBox.Test";

            BlackBoxManagerThreaded logManager = new BlackBoxManagerThreaded();

            EventConsoleWriter  consoleWriter   = new EventConsoleWriter();
            //EventFileWriter     fileWriter      = new EventFileWriter();
            //EventWinLogWriter   winLogWriter    = new EventWinLogWriter("BlackBoxTest", "BlackBox");
            //EventTSqlWriter     sqlLogWriter    = new EventTSqlWriter("BlackBoxTest", "Data Source=ds;Initial Catalog=db;User Id=lambert;Password=brabantsenachtenzijnlang");
            EventMockWriter     mockWriter      = new EventMockWriter();
            
            logManager.RegisterFallbackWriter(consoleWriter.Write);

            logManager.RegisterWriter(BlackBoxUtilities.GetAllEventTypes(), consoleWriter.Write);
            //logManager.RegisterWriter(BlackBoxUtilities.GetAllEventTypes(), fileWriter.Write);
            //logManager.RegisterWriter(BlackBoxUtilities.GetAllEventTypes(), winLogWriter.Write);
            //logManager.RegisterWriter(BlackBoxUtilities.GetAllEventTypes(), mockWriter.Write);
            //logManager.RegisterWriter(BlackBoxUtilities.GetAllEventTypes(), sqlLogWriter.Write);

            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("id", 15);
            parameters.Add("name", "lambert");
            logManager.Write(EventTypes.Trace, "Hello Parameters!", parameters);
            
            logManager.Write(new ArgumentNullException("id"));

            Log.SetManager(logManager);

            parameters = new Dictionary<string, object>();
            parameters.Add("name", "lambert");
            parameters.Add("id", 2);
            parameters.Add("money", 4343f);
            Log.Trace("Parameter test", parameters);

            Log.Critical("Critical world!");
            Log.Debug("Debug world!");
            Log.Trace("Trace world!");
            Log.Warning("Warning world!");
            Log.Error("Error world!");
            Log.Error(new ArgumentNullException("name"));

            Console.WriteLine("Press any key to end program.");
            Console.ReadKey();

            Console.WriteLine("Disposing log manager...");
            Console.WriteLine(mockWriter.EventMessages.Count + " events writen.");
            System.Threading.Thread.Sleep(250);
        }
    }
}
